<style type="text/css">
.adwit_banner {
    font-size:12px;
    margin:5px;
    float: left;
    text-align:center;}
</style>
<script type="text/javascript">
function _adwit_change_post_type(){
    document.awitfrm.submit();
}
</script>
<div class="wrap">
  <div class="icon32" id="icon-edit"><br></div>
  <h2><?php echo __('Adwit Banner Manager - Choix des emplacements publicitaires', 'adwit')?>
  </h2> 
<?php echo __('Choisissez le type de page sur lequel vous désirez des publicités, puis glissez et déposez simplement les formats d\'annonces que vous désirez incorporer à votre blog', 'adwit') ?>
</div>
<div style="margin-top: 10px;margin-left: 30px;width: 240px;">
    <form name="awitfrm" action="/wp-admin/admin.php?page=adwit_setup" method="post">
<?php echo __('Post type','adwit') ?>
      <select id="post_type" name="post_type" onchange="_adwit_change_post_type();">
        <option value="page" <?php echo ($_POST['post_type']=='page' ? ' selected=true' : '');?>><?php echo __('Page', 'adwit') ?></option>
        <option value="post" <?php echo ($_POST['post_type']=='post' ? ' selected=true' : '');?>><?php echo __('Post', 'adwit') ?></option>
        <option value="home" <?php echo ($_POST['post_type']=='home' ? ' selected=true' : '');?>><?php echo __('Home', 'adwit') ?></option>
        <option value="search" <?php echo ($_POST['post_type']=='search' ? ' selected=true' : '');?>><?php echo __('search', 'adwit') ?></option>
    </select> 
    </form>
</div>
<div id="view_post_type">
<?php

if (file_exists(ADWIT_BANNER_MANAGER_PATH . '/views/'.$view_page.'.php')) {
    $adwit_ban_list = _get_bann_list();
    include(ADWIT_BANNER_MANAGER_PATH . '/views/'.$view_page.'.php');
}
?>
</div>
<?php
  function adwit_get_width_and_height_for_div($adwit_ban_list, $obj) {
    return 'width: '.$adwit_ban_list[$obj['width']."x".$obj['height']]['width'].';height: '.$adwit_ban_list[$obj['width']."x".$obj['height']]['height'];
  }
?>
<div style="float: left; margin-top: 15px;  margin-left: 50px; width:340px;  border: 1px solid #777777;">
<?php
  foreach ($adwit_ban_list as $bkey => $bval){
    ?>
<div id="<?php echo 'ban'.$bkey?>"   class="<?php echo $bval['class']?>" style="width: <?php echo $bval['width']?>; height: <?php echo $bval['height']?>; background-color: <?php echo $bval['bgcolor']?>;"><img src="<?php echo ADWIT_BANNER_IMAGES; ?>/<?php echo $bkey;?>.png" alt=""/></div>
<?php
  }?>
</div>
<script type="text/javascript">
    new Draggable('ban468x60', {revert: true });
    new Draggable('ban728x90', { revert: true });
    new Draggable('ban160x600', { revert: true });
    new Draggable('ban120x600', { revert: true });
    new Draggable('ban200x200', { revert: true });
    new Draggable('ban250x250', { revert: true });
    new Draggable('ban300x250', { revert: true });
    new Draggable('ban120x240', { revert: true });
    new Draggable('ban336x280', { revert: true });
    new Draggable('ban180x150', { revert: true });
    new Draggable('ban125x125', { revert: true });
    new Draggable('ban234x60', { revert: true });

    var posttype = document.getElementById('post_type');
    var ptype = posttype.options[posttype.selectedIndex].value;

    function clear_my_obj(obj) {
        obj.innerHTML='';
        obj.style.height='1px';
        obj.style.width='1px';
        obj.style.backgroundColor='#ffffff';
        obj.style.lineHeight='5px';
        //alert(obj.id);
        wp_remove_adwit_banner(ptype, obj.id)
          /* todo appel interne pour desactivé une zone (qui lui appeller adwit) */
    }

    function wp_add_adwit_banner(post_type, pos_v, pos_h, bsize) {
        var url = '/wp-admin/admin.php';
        new Ajax.Request(url, {
            method: 'post',
            parameters: { page: 'adwit_setup',
                adwit_action: 'adwit_add_banner',
                post_type: post_type,
                pos_v: pos_v,
                pos_h: pos_h,
                bsize: bsize
            },
            onSuccess: function(transport) {
                //somme proccess
            }
        });
    }

    function wp_remove_adwit_banner(post_type, pos) {
        var url = '/wp-admin/admin.php';
        new Ajax.Request(url, {
            method: 'post',
            parameters: { page: 'adwit_setup',
                adwit_action: 'adwit_remove_banner',
                post_type: post_type,
                pos: pos
            },
            onSuccess: function(transport) {
                //somme proccess
            }
        });
    }

    function copy_style_element(source, dest) {
        $(source).style.width=dest.style.width;
        $(source).style.height=dest.style.height;
        $(source).style.backgroundColor=dest.style.backgroundColor;
        $(source).style.lineHeight=dest.style.lineHeight;
        $(source).update(dest.innerHTML);
    }
</script>


<?php
  #  $paragraphes = preg_match_all("/(<p(.*?)<\/p>)/", "<p > partie<br> 1</p><p> partie<br> 2</p><p> partie3</p><p> partie<br> 4</p>", $result);
  #$two_array = array_chunk($result[0], ceil(count($result[0])/2));
  #$result = implode(array_merge($two_array[0], array('moncontenu du milieu'), $two_array[1]))  
?>